package com.yang.controller;

import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.yang.entity.Roles;
import com.yang.entity.User;
import com.yang.model.MenuBean;
import com.yang.service.ResourceService;
import com.yang.service.RoleService;
import com.yang.service.UserService;

/**
 * 描述：首页的相关控制器
 * 版本：1.0
 * 作者： 杨建全
 * 创建时间：2016年3月23日  上午10:03:18
 */
@Controller
public class IndexController {
	
	@Autowired
	private UserService userService;
	@Autowired
	private RoleService roleService;
	@Autowired
	private ResourceService resourceService;
	
	/**
	 * 跳转到管理员主页
	 * @return
	 */
	@RequestMapping("/adminIndex")
	public String getIndex(HttpSession session,HttpServletRequest request){
		//读取菜单
		Subject userSubject = SecurityUtils.getSubject();
		User user = (User) userSubject.getSession().getAttribute("currentUser");
		if(null!=user){
			MenuBean mb = resourceService.getAllMenus(user.getRoles());
			request.setAttribute("menuBean", mb);
			return "/admin-index";
		}
		return "redirect:login";
	}
}
